Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
eslint-plugin-prettier
Advanced tools
The eslint-plugin-prettier npm package integrates Prettier, an opinionated code formatter, with ESLint, a tool for identifying and reporting on patterns in JavaScript. It allows you to use Prettier as an ESLint rule and reports differences as individual ESLint issues.
Code Formatting
Automatically format code to match the style specified in your Prettier configuration when you run ESLint with the --fix option.
"scripts": { "lint": "eslint --fix 'src/**/*.js'" }
Integration with ESLint Rules
Use Prettier to enforce a consistent code style while still using ESLint to catch possible errors.
{ "extends": ["plugin:prettier/recommended"] }
Customizable Formatting Rules
Override default Prettier options to tailor the formatting to your project's needs.
{ "rules": { "prettier/prettier": ["error", { "singleQuote": true, "parser": "flow" }] } }
Turns off all ESLint rules that are unnecessary or might conflict with Prettier. It's used to avoid conflicts between ESLint and Prettier formatting rules.
Formats your JavaScript using Prettier followed by ESLint --fix. It's similar to eslint-plugin-prettier but applies Prettier formatting first and then runs ESLint's auto-fixing feature.
Runs Prettier as a Stylelint rule and reports differences as individual Stylelint issues. It's similar to eslint-plugin-prettier but for stylesheets and integrates with Stylelint instead of ESLint.
Disables TSLint formatting rules that might conflict with Prettier. It's similar to eslint-config-prettier but for TypeScript projects using TSLint instead of ESLint.
Runs Prettier as an ESLint rule and reports differences as individual ESLint issues.
If your desired formatting does not match Prettier’s output, you should use a different tool such as prettier-eslint instead.
Please read Integrating with linters before installing.
.eslintrc*
)eslint.config.js
)Svelte
supportarrow-body-style
and prefer-arrow-callback
issueerror: Insert `,` (prettier/prettier) at pkg/commons-atom/ActiveEditorRegistry.js:22:25:
20 | import {
21 | observeActiveEditorsDebounced,
> 22 | editorChangesDebounced
| ^
23 | } from './debounced';;
24 |
25 | import {observableFromSubscribeFunction} from '../commons-node/event';
error: Delete `;` (prettier/prettier) at pkg/commons-atom/ActiveEditorRegistry.js:23:21:
21 | observeActiveEditorsDebounced,
22 | editorChangesDebounced
> 23 | } from './debounced';;
| ^
24 |
25 | import {observableFromSubscribeFunction} from '../commons-node/event';
26 | import {cacheWhileSubscribed} from '../commons-node/observable';
2 errors found.
./node_modules/.bin/eslint --format codeframe pkg/commons-atom/ActiveEditorRegistry.js
(code from nuclide).
npm install --save-dev eslint-plugin-prettier eslint-config-prettier
npm install --save-dev --save-exact prettier
eslint-plugin-prettier
does not install Prettier or ESLint for you. You must install these yourself.
This plugin works best if you disable all other ESLint rules relating to code formatting, and only enable rules that detect potential bugs. If another active ESLint rule disagrees with prettier
about how code should be formatted, it will be impossible to avoid lint errors. Our recommended configuration automatically enables eslint-config-prettier
to disable all formatting-related ESLint rules.
.eslintrc*
)For legacy configuration, this plugin ships with a plugin:prettier/recommended
config that sets up both eslint-plugin-prettier
and eslint-config-prettier
in one go.
Add plugin:prettier/recommended
as the last item in the extends array in your .eslintrc*
config file, so that eslint-config-prettier
has the opportunity to override other configs:
{
"extends": ["plugin:prettier/recommended"]
}
This will:
prettier/prettier
rule.arrow-body-style
and prefer-arrow-callback
rules which are problematic with this plugin - see the below for why.eslint-config-prettier
config which will turn off ESLint rules that conflict with Prettier.eslint.config.js
)For flat configuration, this plugin ships with an eslint-plugin-prettier/recommended
config that sets up both eslint-plugin-prettier
and eslint-config-prettier
in one go.
Import eslint-plugin-prettier/recommended
and add it as the last item in the configuration array in your eslint.config.js
file so that eslint-config-prettier
has the opportunity to override other configs:
const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommended');
module.exports = [
// Any other config imports go at the top
eslintPluginPrettierRecommended,
];
This will:
prettier/prettier
rule.arrow-body-style
and prefer-arrow-callback
rules which are problematic with this plugin - see the below for why.eslint-config-prettier
config which will turn off ESLint rules that conflict with Prettier.Svelte
supportWe recommend to use eslint-plugin-svelte
instead of eslint-plugin-svelte3
because eslint-plugin-svelte
has a correct eslint-svelte-parser
instead of hacking.
When use with eslint-plugin-svelte3
, eslint-plugin-prettier
will just ignore the text passed by eslint-plugin-svelte3
, because the text has been modified.
If you still decide to use eslint-plugin-svelte3
, you'll need to run prettier --write *.svelte
manually.
arrow-body-style
and prefer-arrow-callback
issueIf you use arrow-body-style or prefer-arrow-callback together with the prettier/prettier
rule from this plugin, you can in some cases end up with invalid code due to a bug in ESLint’s autofix – see issue #65.
For this reason, it’s recommended to turn off these rules. The plugin:prettier/recommended
config does that for you.
You can still use these rules together with this plugin if you want, because the bug does not occur all the time. But if you do, you need to keep in mind that you might end up with invalid code, where you manually have to insert a missing closing parenthesis to get going again.
If you’re fixing large of amounts of previously unformatted code, consider temporarily disabling the prettier/prettier
rule and running eslint --fix
and prettier --write
separately.
Note: While it is possible to pass options to Prettier via your ESLint configuration file, it is not recommended because editor extensions such as
prettier-atom
andprettier-vscode
will read.prettierrc
, but won't read settings from ESLint, which can lead to an inconsistent experience.
The first option:
An object representing options that will be passed into prettier. Example:
{
"prettier/prettier": [
"error",
{
"singleQuote": true,
"parser": "flow"
}
]
}
NB: This option will merge and override any config set with .prettierrc
files
The second option:
An object with the following options
usePrettierrc
: Enables loading of the Prettier configuration file, (default: true
). May be useful if you are using multiple tools that conflict with each other, or do not wish to mix your ESLint settings with your Prettier configuration. And also, it is possible to run prettier without loading the prettierrc config file via the CLI's --no-config option or through the API by calling prettier.format() without passing through the options generated by calling resolveConfig.
{
"prettier/prettier": [
"error",
{},
{
"usePrettierrc": false
}
]
}
fileInfoOptions
: Options that are passed to prettier.getFileInfo to decide whether a file needs to be formatted. Can be used for example to opt-out from ignoring files located in node_modules
directories.
{
"prettier/prettier": [
"error",
{},
{
"fileInfoOptions": {
"withNodeModules": true
}
}
]
}
The rule is auto fixable -- if you run eslint
with the --fix
flag, your code will be formatted according to prettier
style.
@prettier/plugin-eslint | eslint-config-prettier | eslint-plugin-prettier | prettier-eslint | prettier-eslint-cli |
---|---|---|---|---|
@prettier/plugin-eslint | eslint-config-prettier | eslint-plugin-prettier | prettier-eslint | prettier-eslint-cli |
---|---|---|---|---|
See CONTRIBUTING.md
Detailed changes for each release are documented in CHANGELOG.md.
5.2.1
ac036cc
Thanks @OrlovAlexei! - build(deps): Bump synckit from 0.8.6 to 0.9.1FAQs
Runs prettier as an eslint rule
The npm package eslint-plugin-prettier receives a total of 6,989,185 weekly downloads. As such, eslint-plugin-prettier popularity was classified as popular.
We found that eslint-plugin-prettier demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.